//
//  SpotSubjoinServeCell.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/7/5.
//

import UIKit

protocol SpotSubjoinServeCellDelegate:class  {
    func SpotSubjoinServeClickedType(clickType:SpotInfoCellType)
}

class SpotSubjoinServeCell: UITableViewCell {

    @IBOutlet weak var subjoinlab: UILabel!
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var protectView: UIView!
    @IBOutlet weak var protectLab: UILabel!
    @IBOutlet weak var protectMegLab: UILabel!
    @IBOutlet weak var collectionView: UIView!
    @IBOutlet weak var collectionLab: UILabel!
    @IBOutlet weak var collectionMsgLab: UILabel!
    
    var orderInfoModel:OrderListModel!
    weak var delegate:SpotSubjoinServeCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        self.contentView.backgroundColor = UIColor.init(hexString: "#F3F3F3")
        self.contentView.layer.cornerRadius = 5
        self.contentView.layer.masksToBounds = true
        self.collectionView.layer.cornerRadius = 5
        self.protectView.layer.cornerRadius = 5
        self.bgView.layer.cornerRadius = 5
        
        let addressTap = UITapGestureRecognizer.init(target: self, action: #selector(protectAction))
        self.protectView.isUserInteractionEnabled = true
        self.protectView.addGestureRecognizer(addressTap)
        
        let lookExpressTap = UITapGestureRecognizer.init(target: self, action: #selector(collectionAction))
        self.collectionView.isUserInteractionEnabled = true
        self.collectionView.addGestureRecognizer(lookExpressTap)
        
        self.bgView.layer.shadowOffset = CGSize.init(width: 0, height: 1)
        self.bgView.layer.shadowOpacity = 1
        self.bgView.layer.shadowRadius = 2
        self.bgView.layer.shadowColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.2).cgColor
        self.setValueUI()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func setValueUI() {
        self.protectLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_spot_support)
        self.collectionLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_spot_collectionDelivery)
        self.subjoinlab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_spot_optionalServe)

    }
    
    func setOrderInfoModel(orderInfoModel:OrderListModel) {
        self.orderInfoModel = orderInfoModel
        if (orderInfoModel.isInsure != 0) {
            self.protectMegLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_spot_pleaseSelect)
            self.protectMegLab.textColor = UIColor.init(hexString: "#B2B2B2")
        } else {
            self.protectMegLab.text = "MMK" + orderInfoModel.insureAmount
            self.protectMegLab.textColor = UIColor.init(hexString: "#333333")
        }
        if orderInfoModel.isCollection != 1 {
            self.collectionMsgLab.text = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.WL_spot_pleaseSelect)
            self.collectionMsgLab.textColor = UIColor.init(hexString: "#B2B2B2")
        } else {
            self.collectionMsgLab.text = "MMK" + orderInfoModel.collectionFreightAmount
            self.collectionMsgLab.textColor = UIColor.init(hexString: "#333333")
        }
    }

    @objc func protectAction()  {
        delegate?.SpotSubjoinServeClickedType(clickType: SpotInfoCellType.Spot_Protect_Type)
    }
    
    @objc func collectionAction()  {
        delegate?.SpotSubjoinServeClickedType(clickType: SpotInfoCellType.Spot_Protect_Type)
    }
    @IBAction func selectSiteBtn(_ sender: UIButton) {
        sender.isEnabled = !sender.isSelected
        if sender.tag == 100 {
            if sender.isSelected {
                let btn:UIButton = self.viewWithTag(101)! as! UIButton
                btn.isSelected = false
            }
        } else if sender.tag == 101 {
            if sender.isSelected {
                let btn:UIButton = self.viewWithTag(100)! as! UIButton
                btn.isSelected = false
            }
        }
    }
}
